package com.demo.yuanzi.util;

import com.demo.yuanzi.dao.YuanziSaRoleDao;
import com.demo.yuanzi.dao.YuanziSaUserDao;
import com.demo.yuanzi.entity.YuanziSaPermission;
import com.demo.yuanzi.entity.YuanziSaRole;
import com.demo.yuanzi.entity.authDTO.YuanZiRoleDTO;
import com.demo.yuanzi.entity.authDTO.YuanZiUserDTO;
import com.demo.yuanzi.service.YuanziSaRoleService;
import com.demo.yuanzi.service.YuanziSaUserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.security.Permission;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * 待修改，当一个用户具有多种角色时如何完成
 * 非空判断等
 */
@Component
public class LoginSaRoleAndPermission {
    @Resource
    private YuanziSaUserService yuanziSaUserService;


    //该用户id具有的权限集合

    public List<String> getPermissionList(Integer useId){
        List<String> permissionByUserId= yuanziSaUserService.getPermissionByUserId(useId);
        return permissionByUserId;
    }
    //该用户id具有的角色集合
    public List<String> getRoleList(Integer useId){
        List<YuanZiUserDTO>  roles = yuanziSaUserService.getRoleByUserId(useId);
        List<String> collect = roles.stream().map(YuanZiUserDTO::getRolename).collect(Collectors.toList());

        return collect;
    }
}
